<?php

/**
 * This is the model class for table "{{clarisHistory}}".
 *
 * The followings are the available columns in table '{{clarisHistory}}':
 * @property string $fio
 * @property string $telefon
 * @property string $zakaz_kurera
 * @property string $adres
 * @property string $gorod
 * @property string $data_sozdaniya
 * @property string $tip_tehniki
 * @property string $brend
 * @property string $model
 * @property string $rekomendation
 * @property string $price
 * @property string $title_page
 * @property string $link_page
 * @property string $historyId
 */
class ClarisHistory extends CActiveRecord {

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{clarisHistory}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('fio, telefon, zakaz_kurera, adres, gorod, data_sozdaniya, tip_tehniki, brend, model, rekomendation, title_page, link_page', 'length', 'max' => 255),
            array('price', 'safe'),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('fio, telefon, zakaz_kurera, adres, gorod, data_sozdaniya, tip_tehniki, brend, model, rekomendation, price, title_page, link_page, historyId', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            "fio" => 'Имя пользователя',
            "telefon" => 'Телефон',
            "zakaz_kurera" => 'Курьер',
            "adres" => 'Адрес',
            "gorod" => 'Город',
            "data_sozdaniya" => 'Дата',
            "tip_tehniki" => 'Тип техники',
            "brend" => 'Бренд',
            "model" => 'Модель',
            "rekomendation" => 'Рекомендация',
            "price" => 'Цена',
            "title_page" => 'заголовок страницы с которой ушла заявка',
            "link_page" => 'Страница',
            'historyId' => 'ID',
            'type' => 'Тип',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     *
     * Typical usecase:
     * - Initialize the model fields with values from filter form.
     * - Execute this method to get CActiveDataProvider instance which will filter
     * models according to data in model fields.
     * - Pass data provider to CGridView, CListView or any similar widget.
     *
     * @return CActiveDataProvider the data provider that can return the models
     * based on the search/filter conditions.
     */
    public function search() {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria = new CDbCriteria;
        $criteria->order = '"historyId" desc';

        $criteria->compare('fio', $this->fio, true);
        $criteria->compare('telefon', $this->telefon, true);
        $criteria->compare('zakaz_kurera', $this->zakaz_kurera, true);
        $criteria->compare('adres', $this->adres, true);
        $criteria->compare('gorod', $this->gorod, true);
        $criteria->compare('data_sozdaniya', $this->data_sozdaniya, true);
        $criteria->compare('tip_tehniki', $this->tip_tehniki, true);
        $criteria->compare('brend', $this->brend, true);
        $criteria->compare('model', $this->model, true);
        $criteria->compare('rekomendation', $this->rekomendation, true);
        $criteria->compare('price', $this->price, true);
        $criteria->compare('title_page', $this->title_page, true);
        $criteria->compare('link_page', $this->link_page, true);
        $criteria->compare('historyId', $this->historyId, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
            'pagination' => array('pageSize' => 100),
        ));
    }

    /**
     * Returns the static model of the specified AR class.
     * Please note that you should have this exact method in all your CActiveRecord descendants!
     * @param string $className active record class name.
     * @return ClarisHistory the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

}
